package com.jblv.frame.demo;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author happyonion.yangtao
 * @version 1.0
 * @title KafkaSendMsg
 * @projectName jblv-frame
 * @packageName com.jblv.web
 * @description
 * @date Create at 2020/4/17 11:54
 * @since jdk1.8
 */
//@Component
@RequestMapping("/kafka")
@RestController
public class KafkaSendMsg {
    private Log log = LogFactory.getLog(KafkaSendMsg.class);

     @Autowired
     private  KafkaTemplate kafkaTemplate;
//    private final KafkaTemplate kafkaTemplate;

//    @Autowired
//    public KafkaSendMsg(KafkaTemplate kafkaTemplate) {
//        this.kafkaTemplate = kafkaTemplate;
//
//
//        for(int i=0;i<5;i++) {
//            this.SendMessge("hello "+i);
//        }
//    }

    @RequestMapping("/")
    public void SendMessge(String msg) {

        log.info("send send msg :"+msg);

        this.kafkaTemplate.send("springboot-topic1", msg);

    }

}
